﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MongoDB.Bson;
using MongoDB.Driver.Linq;
using MongoDB.Driver;
using System.Data.Entity;
using XTeam.Document.Entities.Words;
using MongoDB.Bson.Serialization;
using MongoDB.Driver.Builders;
using XTeam.Core.Abstract;
using XTeam.Document.Entities;
namespace XTeam.Documents.DataAccess
{
    public class MongoDB : MongoDBContext
    {

        public MongoCollection<WordsEntity> WordsTable
        {
            get
            {
                return _db.GetCollection<WordsEntity>("WordsTable");
            }
        }
        /// <summary>
        /// 初始化
        /// </summary>
        public override void Initial()
        {
            if (!BsonClassMap.IsClassMapRegistered(typeof(WordsEntity)))
            {
                BsonClassMap.RegisterClassMap<WordsEntity>().MapIdField(i => i.Word);
            }

            if (!BsonClassMap.IsClassMapRegistered(typeof(ArticleClassifyEntity)))
            {
                BsonClassMap.RegisterClassMap<ArticleClassifyEntity>(pcm =>
                {
                    pcm.AutoMap();
                    pcm.UnmapProperty(i => i.Children);
                    pcm.UnmapProperty(i => i.Parent);
                    pcm.MapIdProperty(i => i.ClassId);
                });
            }


            this.MapToCollection<WordsEntity>("WordsTable");
            this.MapToCollection<ArticleClassifyEntity>("ArticleClassTable");
        }
    }
}
